﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AGameOfThrones.tokens
{
    /// <summary>
    /// Interaction logic for ordertokens.xaml
    /// </summary>
    public partial class ordertokens : UserControl
    {
        public Panel Panel { get { return ordertokens_panel; } }

        public ordertokens()
        {
            InitializeComponent();
        }

        private void ordertokens_control_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(piece.piece)))
            {
                piece.piece t = e.Data.GetData(typeof(piece.piece)) as piece.piece;
                Panel parent = t.Parent as Panel;

                if (parent != ordertokens_panel)
                {
                    parent.Children.Remove(t);

                    ordertokens_panel.Children.Add(t);
                    t.Margin = new Thickness(0, 0, 0, 0);
                }
            }
        }

        private void ordertokens_control_DragOver(object sender, DragEventArgs e)
        {
            Console.WriteLine("Dragging over order tokens");
        }

        private void ordertokens_control_Loaded(object sender, RoutedEventArgs e)
        {
            game.house h = this.DataContext as game.house;            
            if (h != null)
            {
                for (int i = 0; i < h.OrderTokens.Count; i++)
                {
                    game.ordertoken ordertoken = h.OrderTokens[i];
                    piece.ordertoken piece = new piece.ordertoken();
                    piece.DataContext = ordertoken;
                    ordertokens_panel.Children.Add(piece);
                    ordertoken.PieceName = ordertoken.PieceName;
                    ordertoken.Position.Panel = ordertokens_panel.Name;
                    ordertoken.Position.X = 0;
                    ordertoken.Position.Y = 0;
                }
            }
        }
    }
}
